﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XGame
{

    /// <summary>
    /// The XConstants class contains a list of constants that are used throughout the input system.
    /// </summary>
    public static class XConstants
    {

        /// <summary>
        /// The ButtonType enumeration lists the different supported
        /// button types that the XMouse class will handle and raise events on.
        /// </summary>
        public enum ButtonType
        {

            /// <summary>
            /// The left mouse button
            /// </summary>
            LeftButton,

            /// <summary>
            /// The right mouse button
            /// </summary>
            RightButton,

            /// <summary>
            /// The middle mouse button
            /// </summary>
            MiddleButton,

            /// <summary>
            /// The value of the scroll wheel has changed.
            /// </summary>
            ScrollWheel,

            /// <summary>
            /// No button
            /// </summary>
            None

        }

        /// <summary>
        /// The default duration for all waiting events in XGame
        /// </summary>
        public static TimeSpan Default { get { return TimeSpan.FromMilliseconds(1000); } }

        /// <summary>
        /// The DefaultColor for the game clear.
        /// </summary>
        public static Color DefaultColor { get { return Color.CornflowerBlue; } }

        /// <summary>
        /// The Default Exit Key for XGame
        /// </summary>
        public static Keys DefaultExitKey { get { return Keys.Escape; } }

        /// <summary>
        /// The default resolution for XGame
        /// </summary>
        public static Vector2 DefaultResolution { get { return new Vector2(1024, 768); } }

    }

    /// <summary>
    /// The ScreenSettings structure contains any variables that may be required by either
    /// the screen or the internal XGame screen system.
    /// </summary>
    public struct XScreenSettings
    {

        /// <summary>
        /// If set to true, the screen that exists underneath the current one
        /// will be drawn first. This has the potential to have recursive calls
        /// go many layers deep, so please be careful.
        /// </summary>
        public Boolean DrawPrevious { get; set; }

        /// <summary>
        /// If set to true, the screen that exists underneath the current one
        /// will be updated first. Just like setting DrawPrevious to true, this
        /// may have unintended side effects and should be used carefully.
        /// </summary>
        public Boolean UpdatePrevious { get; set; }

        /// <summary>
        /// If set to true, after the current screen handles any sort of event
        /// the next screen in the stack may also receive the same events.
        /// </summary>
        public Boolean EventsPropigate { get; set; }

        /// <summary>
        /// A default settings object that makes managing screen settings relatively painless
        /// </summary>
        public static readonly XScreenSettings Default = new XScreenSettings { DrawPrevious = true, UpdatePrevious = true, EventsPropigate = false };

    }

    /// <summary>
    /// The settings structure houses all the individual settings that
    /// the XGame Handler class needs throughout the lifetime of the game
    /// </summary>
    public struct XGameSettings
    {

        /// <summary>
        /// The color used whenever the graphics device is cleared for drawing.
        /// </summary>
        public Color ClearColor { get; set; }

        /// <summary>
        /// The exit key that is used whenever the XGame handler
        /// needs to have a button press to exit the game.
        /// 
        /// It is only used whenever there are no screens in the stack
        /// and the Handler class must be explicitly ended.
        /// </summary>
        public Keys ExitKey { get; set; }

        /// <summary>
        /// The defined width and height of the game window.
        /// </summary>
        public Vector2 Resolution { get; set; }

        /// <summary>
        /// A Boolean flag that indicates whether or not the game is full screen.
        /// </summary>
        public Boolean FullScreen { get; set; }

        /// <summary>
        /// A Boolean flag that indicates whether or not the Windows mouse cursor is visible.
        /// </summary>
        public Boolean ShowCursor { get; set; }

        /// <summary>
        /// If true, the reported cursor positions will never
        /// leave the bounds of the game.
        /// </summary>
        public Boolean ConstrainCursor { get; set; }

        /// <summary>
        /// If true, the update routine will be allowed to continue even if the window is not active
        /// 
        /// Please note that this has the side effect of disabling off all input handling
        /// as well as any in-game events that require processing on a screen.
        /// </summary>
        public Boolean UpdateWhileInactive { get; set; }

        /// <summary>
        /// If true, the draw routine will be allowed to continue even if the window is not active
        /// </summary>
        public Boolean DrawWhileInactive { get; set; }

        /// <summary>
        /// The MouseDelay timespan property determines how long to wait before allowing a MouseHold event to be raised.
        /// Please note that, after a MouseHold event is raised, it will not be raised again until the TimeSpan is satisfied
        /// </summary>
        public TimeSpan MouseDelay { get; set; }

        /// <summary>
        /// The KeyDelay timespan property determines how long a key is to be suppressed after being pressed down.
        /// </summary>
        public TimeSpan KeyDelay { get; set; }


        /// <summary>
        /// A pre-defined Settings object that sets established defaults for XGame
        /// </summary>
        /// <returns></returns>
        public static readonly XGameSettings Default =
            new XGameSettings
            {
                ClearColor = XConstants.DefaultColor,
                ExitKey = XConstants.DefaultExitKey,
                FullScreen = false,
                Resolution = XConstants.DefaultResolution,
                ShowCursor = true,
                ConstrainCursor = true,
                UpdateWhileInactive = false,
                DrawWhileInactive = false,
                MouseDelay = XConstants.Default,
                KeyDelay = XConstants.Default
            };
        
    }

}
